package cn.iocoder.yudao.framework.validation;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

/**
 * @author 山野羡民
 * @since 2025/01/18
 */
public class PercentValidator implements ConstraintValidator<Percent, Number> {

    @Override
    public boolean isValid(Number value, ConstraintValidatorContext context) {
        // 如果输入为空，默认不校验，即校验通过
        if (value == null) {
            return true;
        }
        // 校验是百分比范围
        return cn.hutool.core.lang.Validator.isBetween(value, 0, 100);
    }

}
